import type { IPointsTransaction } from './integral'
import http from '@/utils/request'

export enum TaskType {
  Week,
  Day,
}

export enum TaskStatus {
  Pending,
  Complete,
}

export interface ITask {
  title: string
  description: string
  type: TaskType
  point: number
  isSystem?: boolean
  children?: string[]
  id?: string
}

export interface IDailyTask {
  completedPoints: number
  recordDate: string
  completedCount: number
  tasks: ITodayTask[]
}

export interface ITodayTask {
  status: TaskStatus
  taskDescription: string
  taskId: string
  taskPoint: number
  taskTitle: string
  taskType: TaskType
}

export interface ITaskRecord extends Pick<IPointsTransaction, 'childId'> {
  startDate: string
  endDate: string
}

export async function addTask(data: ITask): Promise<void> {
  return http('task/add', data)
}

export async function getTask(): Promise<ITask[]> {
  return http('task/list')
}

// 获取今日任务
export async function generateDailyTasks(data: Pick<IPointsTransaction, 'childId'>): Promise<ITodayTask[]> {
  return http('task/today', data)
}

// 删除任务
export async function removeTask(data: Pick<ITask, 'id'>): Promise<void> {
  return http('task/remove', data)
}

// 更新任务状态
export async function changeTaskStatus(data: Pick<ITask, 'id'> & Pick<IPointsTransaction, 'childId'>): Promise<void> {
  return http('task/change', data)
}

// 根据开始和结束日期查询任务记录
export async function queryTaskRecord(data: ITaskRecord): Promise<IDailyTask[]> {
  return http('task/query', data)
}
